package com.qiwenshare.file.util;

import com.alibaba.fastjson2.JSON;
import com.qiwenshare.common.result.RestResult;
import com.qiwenshare.common.result.ResultCodeEnum;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;

/**
 * @author MJ
 * @title qiwen-file
 * @date 2023/10/11 9:39
 * @description TODO
 */
public class ResponseUtil {
    public static void writeResponse(HttpServletResponse response, ResultCodeEnum resultCodeEnum) throws IOException {
        // 让浏览器用utf8来解析返回的数据
        response.setHeader("Content-type", "application/json;charset=UTF-8");
        // 告诉servlet用UTF-8转码，而不是用默认的ISO8859
        response.setCharacterEncoding("UTF-8");
        response.getWriter().print(JSON.toJSONString(RestResult.setResult(resultCodeEnum)));

    }
}
